package com.fairytask.engine.components.table
{
	import com.fairytask.data.BaseData;
	import com.fairytask.engine.components.BaseComponent;
	
	import flash.events.MouseEvent;
	
	/**
	 * 表格 
	 * @author Navy
	 * 
	 */	
	public class TableRow extends BaseComponent
	{
		private var _pos			:int;
		private var _itemArr		:Array	=	[];
		private var _data			:BaseData;
		protected var _itemPox		:Number	=	0;
		
		public function TableRow(isTile:Boolean=false)
		{
			buttonMode	=	true;
			//mouseChildren	=	false;
			if(!isTile)
			{
				addEventListener(MouseEvent.CLICK, onSelect);
				addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick);
			}
		}
		
		private function onSelect(evt:MouseEvent):void
		{
			dispatchEvent(new TableEvent(TableEvent.ROW_SELECT,pos,data));
		}
		
		private function onDoubleClick(evt:MouseEvent):void
		{
			dispatchEvent(new TableEvent(TableEvent.ROW_DOUBLE_CLICK,pos,data));
		}
		
		/**
		 * 添加子项 
		 * @param item
		 * 
		 */
		public function addItem(item:TableItem):void
		{
			_itemArr.push(item);
			item.x	=	_itemPox+Table.colSplit;
			addChild(item);
			_itemPox	+= item.itemWidth;
			
			drawBg();
		}
		
		/**
		 * 一切为了点击 
		 */
		private function drawBg():void
		{
			this.graphics.clear();
			this.graphics.beginFill(0,0);
			this.graphics.drawRect(0,0,_itemPox,this.height);
			this.graphics.endFill();
		}
		
		public function get data():BaseData
		{
			return _data;
		}
		
		public function set data(value:BaseData):void
		{
			_data = value;
		}
		
		public function get pos():int
		{
			return _pos;
		}
		
		public function set pos(value:int):void
		{
			_pos = value;
		}

		public function get itemPox():Number
		{
			return _itemPox;
		}

		public function set itemPox(value:Number):void
		{
			_itemPox = value;
		}

		public function get itemArr():Array
		{
			return _itemArr;
		}
		
		
	}
}